export default {
  data() {
    return {
      drawerLoading: true, //遮罩层
      drawerDisabled: true, //禁用状态
      drawerIds: "", //多选id
      drawerStatus: "", //审核状态
      drawerTableData: [], //表格数据
      drawerTotal: 0, //列表总数
      drawerListUrl: '',//列表地址,
      drawerParams: {},
      newDrawerParams: {},
      drawerCheckedList: [],//选中的对象
      drawerState: false,
    }
  },
  methods: {
    initDrawerTableData(url, drawerParams) {
      this.drawerParams = drawerParams;
      this.drawerListUrl = url;
      this.getDrawerTableData(drawerParams)
    },
    getDrawerTableData(drawerParams) {//获取表格数据
      this.drawerLoading = true;
      this.drawerState = false;
      this.$http.post(this.drawerListUrl, drawerParams).then(res => {
        this.drawerLoading = false;
        console.log(res);
        if (res.code == '200') {
          if (res.totalCount != undefined) {
            this.drawerTotal = res.totalCount;
          }
          this.drawerTableData = res.body;
          this.drawerState = true;
        } else {
          this.drawerTableData = [];
          this.drawerState = true;
        }
      }).catch(error => {
        this.drawerLoading = false;
        this.drawerState = false;
      });
    },
    getDrawerPages(pageNo, pageSize) {
      this.drawerParams.pageNo = pageNo;
      this.drawerParams.pageSize = pageSize;
      this.getDrawerTableData(this.drawerParams);
    },
    drawerQuery() { //条件查询
      this.getDrawerTableData(this.drawerParams);
    },
    checkDrawerIds(val) {
      let drawerIds = [];
      for (let i in val) {
        drawerIds.push(val[i].id);
      }
      this.drawerIds = drawerIds.join(",");
      this.drawerDisabled = val.length > 0 ? false : true;
      this.drawerCheckedList = val;
    },
    //获取选中id和状态drawerStatus
    checkDrawerIdsAndDrawerStatus(val) {
      let drawerIds = [];
      let drawerStatus = [];
      for (let i in val) {
        drawerIds.push(val[i].id);
        drawerStatus.push(val[i].drawerStatus);
      }
      this.drawerIds = drawerIds.join(",");
      this.drawerStatus = drawerStatus.join(",");
      this.drawerDisabled = val.length > 0 ? false : true;
      this.drawerCheckedList = val;
    },
    drawerDeleteBatch(url, drawerIds) { //删除
      this.$confirm('是否确定删除？', '警告', {type: "error"}).then(mes => {
        this.$http.post(url, {ids: drawerIds}).then(res => {
          if (res.code == "200") {
            this.successMessage('删除成功');
            this.getDrawerTableData(this.drawerParams);
          }
        });
      }).catch(error => {
        console.log(error);
      });
    },
    removeBatch(url, roleId, drawerIds) { //移除
      this.$confirm('确定移除吗？', '提示', {type: "error"}).then(mes => {
        this.$http.post(url, {roleId: roleId, userdrawerIds: drawerIds}).then(res => {
          if (res.code == "200") {
            this.successMessage('移除成功');
            this.getDrawerTableData(this.drawerParams);
          }
        });
      }).catch(error => {
      });
    },
    priorityBatch(url, drawerIds, priorities, regDefId) { //保存排列循序
      this.$confirm('是否保存排列顺序', '提示', {type: "warning"}).then(mes => {
        this.$http.post(url, {drawerIds: drawerIds, priorities: priorities, regDefId: regDefId}).then(res => {
          if (res.code == "200") {
            this.successMessage('操作成功');
            this.getDrawerTableData(this.drawerParams);
          }
        });
      }).catch(error => {
      });
    },
    prioritysBatchs(url, drawerIds, priorities, drawerDisableds, regDefId) { //保存排列循序四个参数
      this.$confirm('是否保存排序？', '提示', {type: "warning"}).then(mes => {
        this.$http.post(url, {
          drawerIds: drawerIds,
          priorities: priorities,
          drawerDisableds: drawerDisableds,
          defId: regDefId
        }).then(res => {
          if (res.code == "200") {
            this.successMessage('操作成功');
            this.getDrawerTableData(this.drawerParams);
          }
        });
      }).catch(error => {
      });
    },
    prioritysBatch(url, drawerIds, priorities) { //保存排列
      this.$confirm('是否保存排序？', '提示', {type: "warning"}).then(mes => {
        this.$http.post(url, {drawerIds: drawerIds, priorities: priorities}).then(res => {
          if (res.code == "200") {
            this.successMessage('保存成功');
            this.getDrawerTableData(this.drawerParams);
          }
        });
      }).catch(error => {
      });
    },
    revertBatch(url, drawerIds) { //批量还原
      this.$confirm('是否确定还原？', '提示', {type: "warning"}).then(mes => {
        this.$http.post(url, {drawerIds: drawerIds}).then(res => {
          if (res.code == "200") {
            this.successMessage('还原成功');
            this.getDrawerTableData(this.drawerParams);
          }
        });
      }).catch(error => {
      });
    },
    reviewBatch(url, drawerIds) {//批量审核
      this.$confirm('是否批量审核', '提示', {type: "warning"}).then(mes => {
        this.$http.post(url, {drawerIds: drawerIds}).then(res => {
          if (res.code == "200") {
            this.successMessage('审核成功!');
            setTimeout(() => {
              this.getDrawerTableData(this.drawerParams);
            }, 800);
          }
        });
      }).catch(error => {
      });
    }
  }
}
